package service;
import java.util.List;
import mapper.SysFuncRepository;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Import;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RequestMapping;
import common.BaseService;
import entity.SysFunc;

@Service
@Import(BaseService.class)
public class SysFuncService extends BaseService<SysFunc,SysFuncRepository>{
	
	private static Logger logger = Logger.getLogger(SysFuncService.class);  

	@Autowired
   private SysFuncRepository sysFuncRepository;
	 
    @RequestMapping("save")
    public  String save(SysFunc sysFunc){
    	if(sysFunc.getSeqid()==null || sysFunc.getSeqid()==0L){
    		sysFuncRepository.insert(sysFunc);
		}else{
			//save方法表示当实体存在的时候就更新，不存在则插入。但是插入的效率低于insert
			logger.info(sysFuncRepository.updateById(sysFunc));
		}
       return "ok";
    }
    
    @RequestMapping("insert")
    public  String insert(SysFunc sysFunc){
    	sysFuncRepository.insert(sysFunc);
       return "ok";
    }
   
    @RequestMapping("find")
    public List<SysFunc> find(){
    	List<SysFunc> sysFuncList = sysFuncRepository.all();
       return sysFuncList;
       
    }
   

    @RequestMapping("findById")
    public SysFunc findById(long seqid){
    	SysFunc sysFunc = sysFuncRepository.findById(seqid);
       return sysFunc;
    }
    

    
    @RequestMapping("findByPreId")
    public List<SysFunc> findByPreId(long seqid){
    	List<SysFunc> sysFuncs = sysFuncRepository.findByPreId(seqid);
       return sysFuncs;
    }
    
    @RequestMapping("findAllPreFunc")
    public List<SysFunc> findAllPreFunc(){
    	List<SysFunc> sysFuncs = sysFuncRepository.findAllPreFunc();
       return sysFuncs;
    }
    
    @RequestMapping("deleteByIds")
    public void deleteByIds(String [] seqids){
    	for(int i=0;i<seqids.length;i++){
    		sysFuncRepository.deleteById(Long.parseLong(seqids[i]));
//			 Query query = new Query();  
//			 query.addCriteria(Criteria.where("_id").is(seqids[i]));  
//    		 mongoTemplate.remove(query, SysFunc.class);
    	}
    }
	
	
    
}

